home *** CD-ROM | disk | FTP | other *** search
- #include <QD3DGeometry.h>
- #include <QD3DMath.h>
-
- #include <stdlib.h>
-
-
- typedef struct BezierCurve {
- unsigned int order;
- TQ3Point3D controlPoints[];
- } BezierCurve;
-
- TQ3NURBCurveData *BezierToNURBCurve(BezierCurve *bezCurve)
- {
- TQ3NURBCurveData *nurbCurveData; // NURB curve data structure
- unsigned long k; // Order of curve
- TQ3Point3D *b; // Bezier control point vector
- unsigned long i; // Control point or knot index
-
- // Set up local variables for readability.
- k = bezCurve->order;
- b = bezCurve->controlPoints;
-
- // Allocate data structure for new curve.
- nurbCurveData = malloc(sizeof(TQ3NURBCurveData));
- nurbCurveData->order = k;
- nurbCurveData->numPoints = k;
- nurbCurveData->controlPoints = malloc(k*sizeof(TQ3RationalPoint4D));
- nurbCurveData->knots = malloc(2*k*sizeof(float));
-
- // Create the control points.
- for (i = 0; i < k; i++) {
- Q3RationalPoint4D_Set(&nurbCurveData->controlPoints[i],
- b[i].x, b[i].y, b[i].z, 1.0);
- }
-
- // Create the knots.
- for (i = 0; i < k; i++) {
- nurbCurveData->knots[i] = 0.0;
- nurbCurveData->knots[i + k] = 1.0;
- }
-
- // Set attributes here, if desired.
- nurbCurveData->curveAttributeSet = NULL;
-
- return (nurbCurveData);
- }
-